from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPainter
from PyQt6.QtWidgets import QWidget

from gui.panels.filters import PanelFilter
from gui.panels.information import PanelInformation
from gui.panels.message import PanelMessage
from gui.panels.resource import PanelResource
from gui.panels.technology import PanelTechnology
from gui.panels.tool import PanelTool
from gui.panels.world import PanelWorld
from gui.panels.zoning import PanelZoning
from gui.utils.colors import DIM_GREY
from gui.utils.size import WINDOW_WIDTH, WINDOW_HEIGHT
from settings import TITLE
from state.game_state import GameState
from utils.event_bus import EventBus


class MainBoard(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Test Board")
        self.setGeometry(300, 300, WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setWindowTitle(TITLE)
        self.setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.setWindowFlags(
            Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowCloseButtonHint
        )

        self.game_state = GameState()

        # 资源面板
        self.rp = PanelResource(self.game_state, self)
        # 地图面板
        self.wp = PanelWorld(self.game_state, self)
        # 区划面板
        self.zp = PanelZoning(self.game_state, self)
        # 科研面板
        self.tp = PanelTechnology(self.game_state, self)
        # 滤镜面板
        self.fp = PanelFilter(self.game_state, self)
        # 信息面板
        self.ip = PanelInformation(self)
        # 工具面板
        self.lp = PanelTool(self.game_state, self)
        # 消息面板
        self.mp = PanelMessage(self)

        EventBus.register('update_window', self.update)

    def update_info(self, msg: str):
        self.ip.clear()
        self.ip.setText(msg)

    def paintEvent(self, a0):
        painter = QPainter(self)
        painter.setBrush(DIM_GREY)
        painter.drawRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
        super().paintEvent(a0)
